import Vue from 'vue'
import Vuex from 'vuex'
// import axios from 'axios'
import createPersistedState from "vuex-persistedstate"
Vue.use(Vuex)
export default new Vuex.Store({
    // 向外暴露一个vux的实例
    state: {
        apply_form_type: 0, //表单类型  0 1 2 单 双 团
        // state：相当于组件中的data，用于定义的公共数据
        tabs_on: 0,
        com_id: '',
		sex:'',
		age:'',
		userinfo:''
    },
    getters: {
        "GET_MSG": function(state) {
            return state.com_id
        },
        "GET_SEX": function(state) {
            return state.sex
        },
        "SET_AGE": function(state) {
            return state.age
        },
        "SET_USERINFO": function(state) {
            return state.userinfo
        }
    },
    mutations: {
        // 相当于methods，用于定义修改数据的函数
        set_apply_form_type(state, type) {
            state.apply_form_type = type
        },
        "SET_MSG": function(state, com_id) {
            state.com_id = com_id
        },
        "SET_SEX": function(state, sex) {
            state.sex = sex
        },
        "SET_AGE": function(state, age) {
            state.age = age
        },
        "SET_USERINFO": function(state, userinfo) {
            state.userinfo = userinfo
        },
    },
    actions: {
        "SET_MSG": function(state, com_id) {
            state.commit("SET_MSG", com_id)
        },
        "SET_SEX": function(state, sex) {
            state.commit("SET_SEX", sex)
        },
        "SET_AGE": (state, age) => {
            state.commit("SET_AGE", age)
        },
        "SET_USERINFO": (state, userinfo) => {
            state.commit("SET_USERINFO", userinfo)
        },
    },
    plugins: [createPersistedState(
        //想要存储到sessionStorage，配置如下：
        // {
        //     storage: window.sessionStorage
        // }
    )]
    
})